const express=require('express');
const cookieParser=require('cookie-parser');
const cookieSession=require('cookie-session');

var server=express();

//生成cookieSession()密钥
var arr=[];
for(var i=0;i<=1000;i++){
    arr.push('sig_'+Math.random());
}

//session 
server.use(cookieParser());
server.use(cookieSession({
    name:'yexuan_session',                //自定义session名字
    keys:arr,                             //防止出现session劫持，数组越长越难被破解
    maxAge:2*3600*2000                    //自定义session过期时间，此处2小时
}));                                      //cookieSession()一般位于cookieParser()之后

server.use('/',function(req,res){
    /*案例一，统计网页浏览量*/
    if(req.session['count']==null){
        req.session['count']=1;
    }else{
        req.session['count']++;
    }
    console.log(req.session['count']);
    res.send('ok');
});

server.listen(11111);